{% load humanize %}
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>{% if ring %} Ring {{ring}} - {% endif %}Cmatic Scoring</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="">

    <!-- Le styles -->
    <link href="/static/bootstrap/css/bootstrap.css" rel="stylesheet">
    <style type="text/css">
      body {
        padding-top: 60px;
        padding-bottom: 40px;
      }
    </style>
    <link href="/static/bootstrap/css/bootstrap-responsive.css" rel="stylesheet">

    <!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
    <!--[if lt IE 9]>
      <script src="//html5shim.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->

    <!-- Le fav and touch icons -->
    <link rel="shortcut icon" href="images/favicon.ico">
    <link rel="apple-touch-icon" href="images/apple-touch-icon.png">
    <link rel="apple-touch-icon" sizes="72x72" href="images/apple-touch-icon-72x72.png">
    <link rel="apple-touch-icon" sizes="114x114" href="images/apple-touch-icon-114x114.png">
  </head>

  <body>

    <div class="navbar navbar-fixed-top">
      <div class="navbar-inner">
        <div class="container">
          <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </a>
          <a class="brand" href="/">Cmatic</a>
          <div class="nav-collapse">
            <ul class="nav">
              <li {% if not ring %}class="active"{% endif %}><a href="/">Home</a></li>
              {% if ring %}<li class="active"><a href="/{{ring}}">Ring {{ring}}</a></li>{% endif %}
            </ul>
          </div><!--/.nav-collapse -->
        </div>
      </div>
    </div>

    <div class="container">

      <!-- Main hero unit for a primary marketing message or call to action -->
      {% if message %}
        <div class="alert alert-success">
          {{message}}
        </div>
      {% endif %}
      <div class="hero-unit">
        <h1>Welcome {% if ring %}Ring {{ring}}{% endif %} Ringleader</h1>
        {% if not ring %}
          <p>To start off, select the ring number from the left, and then select an event from the right.</p>
        {% else %}
          <p>Now select an event from the right.
          {% if next_event %}
            Your next event appears to be 
            <a href="/event/{{next_event.code}}" target="_blank">
              {{next_event.code}} ({{next_event.form.name}})
            </a>
          {% else %}
            Congradulations! All events are finished!
          {% endif %}
          </p>
        {% endif %}
      </div>

      <!-- Example row of columns -->
      <div class="row">
        <div class="span2">
          <h2>Rings</h2>
          <ul class="nav nav-tabs nav-stacked">
          {% for ring_number, num_events, num_completed in rings %}
            <li {% if ring_number == ring %}class="active"{% endif %}><a href="/{{ring_number}}">
              Ring {{ring_number}}
              <span class="pull-right label"> 
                {{num_completed}}/{{num_events}}
              </span>
            </a></li>
          {% endfor %}
        </ul>
        </div>
        <div class="span10">
          <h2>Events</h2>
          {% if events %}
          <table class="table table-striped table-bordered table-condensed">
            <thead>
              <tr>
                <th>Order</th>
                <th>Code</th>
                <th>Event Name</th>
                <th>Catagories</th>
                <th>#</th>
                <th><span class="pull-right">Status</span></th>
              </tr>
            </thead>
            <tbody>
            {% for event in events %}
              <tr>
                <td>{{event.order}}</td>
                <td><a href="/event/{{event.code}}" target="_blank">{{event.code}}</a></td>  
                <td><a href="/event/{{event.code}}" target="_blank">{{event.form.name}}</a></td>
                <td><a href="/event/{{event.code}}" target="_blank">{{event.division.name}} - {{event.sex.name}} - {{event.age_group.name}}</a></td>
                <td><span class="pull-right">{{event.num_competitors}}</span></td>
                <td>
                  {% if event.completed %}
                    <span class="label label-success pull-right">
                      Finished
                      {% if event.end_time %}
                        {{event.end_time|naturaltime}}
                      {% endif %}
                    </span>
                  {% else %}{% if event.ongoing %}
                    <span class="label label-important pull-right">
                      Started
                      {% if event.start_time %}
                        {{event.start_time|naturaltime}}
                      {% endif %}
                    </span>
                  {% else %}
                    <span class="label pull-right">Not Started</span>
                  {% endif %}{% endif %}
                </td>
              </tr>
            {% endfor %}
            </tbody>
          </table>
          {% else %}
            Select a ring first
          {% endif %}
        </div>
      </div>

      <hr>

      <footer>
        <p>&copy; CalWushu 2012</p>
        {% if times %}
          <p>{{times}}</p>
        {% endif %}
      </footer>

    </div> <!-- /container -->

    <!-- Le javascript
    ================================================== -->
    <!-- Placed at the end of the document so the pages load faster -->
    <script src="/static/bootstrap/js/jquery.js"></script>
    <script src="/static/bootstrap/js/bootstrap-transition.js"></script>
    <script src="/static/bootstrap/js/bootstrap-alert.js"></script>
    <script src="/static/bootstrap/js/bootstrap-modal.js"></script>
    <script src="/static/bootstrap/js/bootstrap-dropdown.js"></script>
    <script src="/static/bootstrap/js/bootstrap-scrollspy.js"></script>
    <script src="/static/bootstrap/js/bootstrap-tab.js"></script>
    <script src="/static/bootstrap/js/bootstrap-tooltip.js"></script>
    <script src="/static/bootstrap/js/bootstrap-popover.js"></script>
    <script src="/static/bootstrap/js/bootstrap-button.js"></script>
    <script src="/static/bootstrap/js/bootstrap-collapse.js"></script>
    <script src="/static/bootstrap/js/bootstrap-carousel.js"></script>
    <script src="/static/bootstrap/js/bootstrap-typeahead.js"></script>

  </body>
</html>
